cmake_minimum_required(VERSION 2.8.3)
project(vs_test)
set(CMAKE_CXX_FLAGS "-std=c++11 ${CMAKE_CXX_FLAGS}")
set( EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin )

set(PTHREAD_LIB "")
find_package(Threads)
if(CMAKE_THREAD_LIBS_INIT)
  string(LENGTH ${CMAKE_THREAD_LIBS_INIT} _length)
  if(_length GREATER 2)
    string(SUBSTRING ${CMAKE_THREAD_LIBS_INIT} 0 2 _prefix)
    if(${_prefix} STREQUAL "-l")
      math(EXPR _rest_len "${_length} - 2")
      string(SUBSTRING ${CMAKE_THREAD_LIBS_INIT} 2 ${_rest_len} PTHREAD_LIB)
    endif()
  endif()
endif() 

#opencv
find_package(OpenCV 3 REQUIRED)
include_directories( ${OpenCV_INCLUDE_DIRS} )
link_directories( ${OpenCV_LIBRARY_DIRS})
message(${OpenCV_INCLUDE_DIRS} )

#Eigen
find_package(Eigen3 REQUIRED)
set(Eigen3_INCLUDE_DIRS ${EIGEN3_INCLUDE_DIRS})
set(Eigen3_LIBRARIES ${EIGEN3_LIBRARIES})
message(${EIGEN3_INCLUDE_DIRS} )
include_directories(${EIGEN3_INCLUDE_DIRS})

#openmp
FIND_PACKAGE( OpenMP REQUIRED)  
if(OPENMP_FOUND)  
message("OPENMP FOUND")  
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")  
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")  
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}")  
endif()  

add_executable(config_test src/main1.cpp)
add_executable(boost_test1 src/boost_sig2_test.cpp)
add_executable(boost_test2 src/boost_sig2_test2.cpp)
add_executable(thread_test1 src/thread_test1.cpp)
target_link_libraries(thread_test1
  ${PTHREAD_LIB}
)
add_executable(thread_test2 src/thread_test2.cpp)
target_link_libraries(thread_test2
  ${PTHREAD_LIB}
)

add_executable(eigen_geometry_test1 src/eigen_geometry_test1.cpp)
target_link_libraries(eigen_geometry_test1
  ${EIGEN3_LIBRARIES}
)

add_executable(eigen_geometry_test2 src/eigen_geometry_test2.cpp)
target_link_libraries(eigen_geometry_test2
  ${EIGEN3_LIBRARIES}
)

ADD_EXECUTABLE( opencv_test1 src/opencv_test1.cpp )
TARGET_LINK_LIBRARIES( opencv_test1
    ${OpenCV_LIBS} )

ADD_EXECUTABLE( opencv_Laplacian src/opencv_Laplacian.cpp )
TARGET_LINK_LIBRARIES( opencv_Laplacian
    ${OpenCV_LIBS} )

ADD_EXECUTABLE( opencv_canny src/opencv_canny.cpp )
TARGET_LINK_LIBRARIES( opencv_canny
    ${OpenCV_LIBS} )

ADD_EXECUTABLE( opencv_camera src/opencv_camera.cpp )
TARGET_LINK_LIBRARIES( opencv_camera
    ${OpenCV_LIBS} )

ADD_EXECUTABLE( opencv_camera_fps src/opencv_camera_fps.cpp )
TARGET_LINK_LIBRARIES( opencv_camera_fps
    ${OpenCV_LIBS} )

add_executable(io_test1 src/io_test1.cpp)

add_executable(openmp_test1 src/openmp_test1.cpp)
TARGET_LINK_LIBRARIES( openmp_test1
-fopenmp )


ADD_EXECUTABLE( opencv_fpm src/ImageIOpfm.cpp src/ImageIOpfm.h )
TARGET_LINK_LIBRARIES( opencv_fpm 
    ${OpenCV_LIBS} )


ADD_EXECUTABLE( opencv_pfm src/opencv_pfm.cpp src/opencv_pfm.hpp )
TARGET_LINK_LIBRARIES( opencv_pfm 
    ${OpenCV_LIBS} )


ADD_EXECUTABLE( sgbm src/stereoSGBM.cpp src/stereoSGBM.h )
TARGET_LINK_LIBRARIES( sgbm
    ${OpenCV_LIBS} )

# ADD_EXECUTABLE( PFMReadWrite src/PFMReadWrite.cpp src/PFMReadWrite.h )
# TARGET_LINK_LIBRARIES( PFMReadWrite
#     ${OpenCV_LIBS} )

